package day8;

import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

import day5.Student;

public class Collection {
	@Test
	public void test(){
	ArrayList<Student> list = new ArrayList<>();
	Student student1 = new Student(001, "zhangsan", 21, "ui03");
	Student student2 = new Student(002, "wanger", 19, "java01");
	Student student3 = new Student(003, "chenliu", 22, "java03");
	list.add(student1);
	list.add(student2);
	list.add(student3);
	for (Student student : list) {
		System.out.println(list);
	}
	System.out.println("——————————————————");
	Set<Student> set = new HashSet<>();
	set.add(student1);
	set.add(student2);
	set.add(student3);
	for (Student student : set) {
		System.out.println(student);
	}
	}
	@Test
	public void test2(){
		HashMap<String, String> map = new HashMap<>();
		map.put("CN", "中华人民共和国");
		map.put("US", "美利坚合众国");
		String key1 = "UK";
		map.put(key1, "大不列颠及北爱尔兰联合王国");
		
		String value1 = map.get("UK");
		System.out.println(value1);
		
		Set<Entry<String, String>> entrySet = map.entrySet();
		for (Entry<String, String> entry : entrySet) {
			String key = entry.getKey();
			String value = entry.getValue();
			System.out.println("key:" + key);
			System.out.println("value：" + value);
		}
		System.out.println("----------------------");
		
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			System.out.println("key:" + key);
			String value = map.get(key);
			System.out.println("value:" + value);
		}
	}
	
	@Test
	public void test4() {
		ArrayList<Student> list = new ArrayList<>();
		Student student1 = new Student(001, "张三", 20, "java01");
		Student student2 = new Student(002,"李四",21,"html02");
		Student student3 = new Student(003, "王五", 19, "java03");
		list.add(student1);
		list.add(student2);
		list.add(student3);
		//List里面的toArray()这个方法将集合转换成数组
		Student[] array = list.toArray(new Student[0]);
		for(int i = 0;i < array.length; i++) {
			System.out.println(array[i]);
		}
		System.out.println("----------------------");
		
		HashSet<Student> set = new HashSet<>();
		set.add(student1);
		set.add(student2);
		set.add(student3);
		Student[] setArray = set.toArray(new Student[0]);
		for (Student student : setArray) {
			System.out.println(student);
		}
		System.out.println("-----------------------");
		Student[] students = new Student[3];
		students[0] = student1;
		students[1] = student2;
		students[2] = student3;
		//数组转换成list集合
//		List<Student> stuList = Arrays.asList(students);
//		for (Student student : stuList) {
//			System.out.println(student);
//		}
	}
}
